package wrs.hcs.functions;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class Login {

	public void admin(WebDriver driver) throws Exception {
		driver.manage().window().maximize();
		String admin = "http://192.168.137.5:9090/login.html";
		driver.get(admin);
		System.out.println(driver.getTitle());
		
		WebElement username = driver.findElement(By.xpath("//div[@id='loginForm']/ul/li[1]/input"));
		WebElement password = driver.findElement(By.xpath("//div[@id='loginForm']/ul/li[2]/input"));
		WebElement button = driver.findElement(By.xpath("//button[@class='btnPrimary']"));
		
		//login to admin page
		username.sendKeys("wrs_admin");
		password.sendKeys("123qweadmin");
		button.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//div[@id='dialog2']/div[1]/div[1]/input")).click();
		driver.findElement(By.xpath("//input[@id='btnAdmType']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		try{
			driver.findElement(By.xpath("//button[@class='btnLogout']"));
			System.out.println("Login successful!");
		}catch(Exception e){
			System.out.println("Login failed.");
		}
		
	}
	
	public void hcs(WebDriver driver, String user) throws Exception {
		driver.manage().window().maximize();
		String hcs = "http://hcs-qa:2112";
		driver.get(hcs);
		System.out.println(driver.getTitle());
		
		WebElement username = driver.findElement(By.xpath("//input[@id='username']"));
		WebElement password = driver.findElement(By.xpath("//input[@id='password']"));
		WebElement button = driver.findElement(By.xpath("//input[@class='btnLogin']"));
		
		//login to hcs
		if(user.equals("admission")){
			username.sendKeys("adm8");
			password.sendKeys("123qweuser");
		}else if(user.equals("nursing")){
			username.sendKeys("10thnw");
			password.sendKeys("123qweuser");
		}else if(user.equals("billing")){
			username.sendKeys("pba1");
			password.sendKeys("123qweuser");
		}
		
		button.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

		
		try{
			driver.findElement(By.xpath("//a[@title='Logout']"));
			System.out.println("Login successful!");
		}catch(Exception e){
			System.out.println("Login failed.");
		}
		
	}
	
}
